//
//  HMMusicViewController.m
//  MymusicPlayer
//
//  Created by 陈尚飞 on 15/11/27.
//  Copyright © 2015年 陈尚飞. All rights reserved.
//

#import "HMMusicViewController.h"
#import "HMMusicModel.h"
#import "UIImage+Circle.h"
#import "HMPlayingViewController.h"
#import "HMMusicTool.h"


@interface HMMusicViewController ()

/// 正在播放的控制器
@property (nonatomic,strong) HMPlayingViewController *playingVc;

@end

@implementation HMMusicViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.rowHeight = 80;
    
}

#pragma 懒加载数据


-(HMPlayingViewController *)playingVc {
    if (_playingVc == nil) {
        self.playingVc = [[HMPlayingViewController alloc] init];
    }
    return _playingVc;

}

#pragma mark - 代理方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //1.取消cell的选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    HMMusicModel *music = [HMMusicTool musics][indexPath.row];
    
    [HMMusicTool setPlayingMusic:music];
    //2.弹出控制器
    [self.playingVc show];
}

#pragma mark - Table view data source


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [HMMusicTool musics].count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *HMMusicCell = @"MusicCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:HMMusicCell];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:HMMusicCell];
    }
    
    //1.取出模型
    HMMusicModel *music = [HMMusicTool musics][indexPath.row];
    cell.imageView.image = [UIImage circleImageWithName:music.singerIcon borderWidth:3.0 borderColor:[UIColor purpleColor]];
    cell.textLabel.text = music.name;
    cell.detailTextLabel.text = music.singer;
    return cell;


}

@end
